package conf

import (
	"fmt"
	"time"

	"gitee.com/liuyongchina/go-library/config"
	"github.com/BurntSushi/toml"
)

type Server struct {
	EndlessConfig `toml:"endless"`
	GinConfig     `toml:"gin"`
}
type EndlessConfig struct {
	ReadTimeout  time.Duration `toml:"read_timeout"`
	WriteTimeout time.Duration `toml:"write_timeout"`
	HttpPort     int           `toml:"http_port"`
}
type GinConfig struct {
	RunMode string `toml:"run_mode"`
}

func (s *Server) getTomlFile() string {
	return "server.toml"
}

func NewServer() *Server {
	return &Server{}
}

//GetConfig dbConf := conf.NewDatabase().GetConfig()
func (s *Server) GetConfig() *Server {
	if _, err := toml.DecodeFile(config.TomlPath+s.getTomlFile(), &s); err != nil {
		fmt.Println(err)
		return s
	}
	s.EndlessConfig.ReadTimeout = s.EndlessConfig.ReadTimeout * time.Millisecond
	s.EndlessConfig.WriteTimeout = s.EndlessConfig.WriteTimeout * time.Millisecond
	return s
}
